package com.roc.web.action.profit;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.DateTime;

public class YsbProfitDetailQuerySearchCondition extends BaseSearchCondition{

	private String beginTime;
	private String endTime;
	private long id;
	private String mchtCd;//商户号
	protected String getOrderPartOfHQL() {
		return " order by ct.stlm_date ";
	}



	@Override
	protected String getRowCountHQL() {
		
		
		if(Constance.isEmpty(beginTime)||Constance.isEmpty(endTime)){
			String date = DateTime.getDay(DateTime.getNow("yyyyMMdd"), "yyyyMMdd", -1);
			beginTime=date;	
			endTime=date;
		}
		
		StringBuffer sb = new StringBuffer();
	     sb.append(" select count(1)                                            \n ");
	     sb.append("   from apsmgm.TBL_CLEAR_TXN ct, apsmgm.t_pos_agent tt      \n ");
	     sb.append("  where ct.remark3 = tt.serial_num                          \n ");
	     sb.append("    and substr(ct.mcht_cd, 0, 4) = '9527'                   \n ");
	     if(Constance.isNotEmpty(mchtCd)){
	     sb.append("    and ct.mcht_cd =").append(mchtCd).append( " \n" ); 
	     }
	     if(Constance.isNotEmpty(String.valueOf(id))){
	     sb.append("    and tt.agent_id =").append(id).append( " \n" );
	     }
	     sb.append("    and substr(ct.remark4, 6, 4) in ('2031',                \n ");
	     sb.append("                                     '1031',                \n ");
	     sb.append("                                     '1011',                \n ");
	     sb.append("                                     '2011',                \n ");
	     sb.append("                                     '1171',                \n ");
	     sb.append("                                     '3011',                \n ");
	     sb.append("                                     '1191',                \n ");
	     sb.append("                                     '1291',                \n ");
	     sb.append("                                     '1391',                \n ");
	     sb.append("                                     '1491',                \n ");
	     sb.append("                                     '1591',                \n ");
	     sb.append("                                     '1691')                \n ");
	     sb.append("    and ct.stlm_date >='"+beginTime+"' and ct.stlm_date<='"+endTime+"'"  );
	     
	     return sb.toString();

	}


	protected String getSearchHQL() {
		if(Constance.isEmpty(beginTime)||Constance.isEmpty(endTime)){
			String date = DateTime.getDay(DateTime.getNow("yyyyMMdd"), "yyyyMMdd", -1);
			beginTime=date;	
			endTime=date;
		}
		
		StringBuffer sb = new StringBuffer();
		sb.append(" select (select o.real_name                                 \n ");
		sb.append("           from apsmgm.t_operators o                        \n ");
		sb.append("          where o.id = tt.agent_id) agentname,              \n ");
		sb.append("        ct.mcht_cd merno,                                   \n ");
		sb.append("        ct.mcht_name mername,                               \n ");
		sb.append("        ct.card_kind_dis,                                   \n ");
		sb.append("        ct.txn_desc,                                        \n ");
		sb.append("        ct.trans_amt,                                       \n ");
		sb.append("        ct.true_fee_ffd,                                    \n ");
		sb.append("        ct.mcht_fee,                                        \n ");
		sb.append("        ct.trans_date_time,                                 \n ");
		sb.append("        ct.pan,                                             \n ");
		sb.append("        ct.key_rsp,                                         \n ");
		sb.append("        ct.term_id,                                         \n ");
		sb.append("        ct.stlm_date                                        \n ");
		 sb.append("   from apsmgm.TBL_CLEAR_TXN ct, apsmgm.t_pos_agent tt      \n ");
		 sb.append("  where ct.remark3 = tt.serial_num                          \n ");
		 sb.append("    and substr(ct.mcht_cd, 0, 4) = '9527'                   \n ");
		 if(Constance.isNotEmpty(mchtCd)){
		     sb.append("    and ct.mcht_cd =").append(mchtCd).append( " \n" ); 
		 }
		 if(Constance.isNotEmpty(String.valueOf(id))){
		     sb.append("    and tt.agent_id =").append(id).append( " \n" );
		 }
		 sb.append("    and substr(ct.remark4, 6, 4) in ('2031',                \n ");
		 sb.append("                                     '1031',                \n ");
		 sb.append("                                     '1011',                \n ");
		 sb.append("                                     '2011',                \n ");
		 sb.append("                                     '1171',                \n ");
		 sb.append("                                     '3011',                \n ");
		 sb.append("                                     '1191',                \n ");
		 sb.append("                                     '1291',                \n ");
		 sb.append("                                     '1391',                \n ");
		 sb.append("                                     '1491',                \n ");
		 sb.append("                                     '1591',                \n ");
		 sb.append("                                     '1691')                \n ");
		 sb.append("    and ct.stlm_date >='"+beginTime+"' and ct.stlm_date<='"+endTime+"'"  );
	     
		return sb.toString();
	}
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		return filedBeanList;
	}


	public String getBeginTime() {
		return beginTime;
	}


	public void setBeginTime(String beginTime) {
		this.beginTime = beginTime;
	}


	public String getEndTime() {
		return endTime;
	}


	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}


	public long getId() {
		return id;
	}


	public void setId(long id) {
		this.id = id;
	}



	public String getMchtCd() {
		return mchtCd;
	}



	public void setMchtCd(String mchtCd) {
		this.mchtCd = mchtCd;
	}




}
